package ui.videos 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import ui.videos.SeekAudioBar;
	
	/**
	 * ...
	 * @author usual
	 */
	public class SeekAudio extends MovieClip 
	{
		public var videoPlayer:*;
		private var _soundPicto:SoundBtn;
		private var _seekAudioBar:SeekAudioBar;
		private var _muteState:Boolean = false;
		private var _forVideoPlayer:Boolean;
		public var volume:Number = 1;
		public function SeekAudio(forVideoPlayer:Boolean=true) 
		{
			_forVideoPlayer = forVideoPlayer;
			addEventListener(Event.ADDED_TO_STAGE, build);
		}
		
		private function build(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, build);
			addElements();
			resize();
		}
		
		public function updateVol(num:Number,_obj:*=null):Number
		{
			volume = num / 100;
			if (videoPlayer && _forVideoPlayer)
			{
				videoPlayer.setVolume(volume);
			}
			if (_forVideoPlayer == false)
			{
				videoPlayer.volume = volume;
			}
			return volume;
		}
		private function addElements():void 
		{
			_soundPicto = new SoundBtn();
			addChild(_soundPicto);
			_soundPicto.buttonMode = true;
			_soundPicto.addEventListener(MouseEvent.CLICK, _onSoundPictoClik);
			_seekAudioBar = new SeekAudioBar();
			addChild(_seekAudioBar);
		}
		
		private function _onSoundPictoClik(e:MouseEvent):void 
		{
			_muteState = !_muteState;
			if (_muteState)_seekAudioBar.mute()
			else _seekAudioBar.unMute()
			
		}
		
		private function resize():void 
		{
			_seekAudioBar.y = ((_soundPicto.height / 2) - (_seekAudioBar.height / 2) + 3);
			_seekAudioBar.x = _soundPicto.x + _soundPicto.width + 9;
		}
		
	}

}